<?php
include "lang.php";
$catId = isset($_REQUEST['catId']) ? $_REQUEST['catId'] : 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Gia An</title>
<?php include "import.php"; ?>
    </head>
    <body onunload="unloadP('productPageScroll')" onload="loadP('productPageScroll')">
<?php include("floating-panel.php"); ?>
        <div class="wrapper">


<?php include("header.php"); ?>
            <div class="main_body">

<?php include("left_menu.php"); ?>
                <div class="main_content">
                    <div class="main_content_header"><?php echo $langs['product.product'] ?></div>

                    <?php
                    include("../action/productAction.php");

                    $current_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;

                    $row_per_page = 9;

                    $productCount = $catId ? countProductOfCategory($catId, '') : countAllProduct('');
                    $total_page = ceil($productCount / $row_per_page);
                    $start_position = ($current_page * $row_per_page) - $row_per_page;

                    $products = getProductOfCategory($catId, $start_position, $row_per_page, '');
                    while ($row = mysql_fetch_array($products)) {
                        buildProductBox($row, $langs);
                    }
                    ?>

                    <div class='paging'>
                        <span class="prn">&lt;&lt;</span>
                        <?php
                        for ($i = 1; $i <= $total_page; $i++) {
                            if ($i == $current_page) {
                                echo "<span>$i</span>";
                            } else {
                                echo "<a href='product.php?catId=$catId&page=$i'>$i</a>";
                            }
                        }
                        ?>			
                        <span class="prn">&gt;&gt;</span>
                    </div>

                </div>
            </div>
        </div>
        <?php include("footer.php"); ?>
    </body>
</html>
